package com.purchase.ml.service.report.asyn;

import com.purchase.ml.bean.req.report.ReportAdminReq;
import com.purchase.ml.bean.req.report.ReportMasterDearSaleReq;
import com.purchase.ml.bean.req.report.ReportOnlineTransactionReq;
import com.purchase.ml.bean.req.report.ReportProductSaleReq;
import com.purchase.ml.bean.res.report.ReportAdminRes;
import com.purchase.ml.bean.res.report.ReportMasterDearSaleRes;
import com.purchase.ml.bean.res.report.ReportOnlineTransactionRes;
import com.purchase.ml.bean.res.report.ReportProductSaleRes;
import com.purchase.ml.bean.res.report.vo.ReportDealerSalesDetailVo;
import com.purchase.ml.bean.res.report.vo.ReportOnlineVo;
import com.purchase.ml.bean.res.report.vo.ReportRegoinCollectVo;
import com.purchase.ml.bean.vo.order.OrderCollectAmtVo;
import com.purchase.ml.mapper.order.SysDealerCollectMapper;
import com.purchase.ml.mapper.order.SysOrderMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.AsyncResult;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;
import java.util.List;
import java.util.concurrent.Future;

/**
 * Created by kyyang on 2021/3/31 18:49
 * 异步查询类
 *
 *
 */
@Component
@Slf4j
public class ReportServiceAsyn {

    @Autowired
    private SysDealerCollectMapper sysDealerCollectMapper;

    @Autowired
    private SysOrderMapper sysOrderMapper;

    @Async
    public Future<ReportAdminRes> queryAdminReportToTalPosAndAmtAndProfit(ReportAdminReq req,int roleType) {
        //查询主经销商时间范围内数据
        ReportAdminRes res = sysDealerCollectMapper.selectAdminReportToTalPosAndAmtAndProfit(req.getDealerId(),req.getStartTime(),req.getEndTime(),roleType);
        return new AsyncResult<>(res);

    }

    @Async
    public Future<List<OrderCollectAmtVo>> queryAdminReportProfitDetail(ReportAdminReq req,int roleType) {
        //查询主经销商时间范围内数据 利润明细
        List<OrderCollectAmtVo> res = sysDealerCollectMapper.selectAdminReportProfitDetail(req.getStartTime(),req.getEndTime(),roleType);
        return new AsyncResult<>(res);
    }

    @Async
    public Future<List<ReportRegoinCollectVo>> queryAdminReportRegoinCollect(ReportAdminReq req,int roleType) {
        //查询主经销商时间范围内区域汇总
        List<ReportRegoinCollectVo> res = sysDealerCollectMapper.selectAdminReportRegoinCollect(req.getStartTime(),req.getEndTime(),roleType);
        return new AsyncResult<>(res);
    }

    @Async
    public Future<List<ReportDealerSalesDetailVo>> queryAdminReportMasterDealerLimit(ReportAdminReq req,int roleType, int index) {
        //查询前10主经销商时间范围内区域汇总
        List<ReportDealerSalesDetailVo> res = sysDealerCollectMapper.selectAdminReportMasterDealerLimit(req.getDealerId(),req.getStartTime(),req.getEndTime(),roleType,index);
        return new AsyncResult<>(res);

    }

    @Async
    public Future<ReportOnlineVo> queryOnlineTransactionReportToTalAmt(ReportOnlineTransactionReq req, int roletypeDealer) {
        ReportOnlineVo bigDecimal =  sysOrderMapper.selectOnlineTransactionReportToTalAmt(req.getStartTime(),req.getEndTime(),roletypeDealer);
        return new AsyncResult<>(bigDecimal);
    }

    @Async
    public Future<List<ReportOnlineTransactionRes>> queryOnlineTransactionReportDetail(ReportOnlineTransactionReq req, int roletypeDealer) {
        List<ReportOnlineTransactionRes> list  =  sysOrderMapper.selectOnlineTransactionReportDetail(req.getStartTime(),req.getEndTime(),req.getStart(),req.getEnd(),roletypeDealer);
        return new AsyncResult<>(list);

    }

    @Async
    public Future<ReportOnlineVo> querMasterDealerSalesToTalAmt(ReportMasterDearSaleReq req, int roletypeMaster) {
        ReportOnlineVo bigDecimal =  sysOrderMapper.selectMasterDealerSalesToTalAmt(req.getStartTime(),req.getEndTime(),req.getOrderState(),req.getDealerName(),roletypeMaster,req.getDealerId());
        return new AsyncResult<>(bigDecimal);
    }

    @Async
    public Future<List<ReportMasterDearSaleRes>> queryMasterDealerSalesDetail(ReportMasterDearSaleReq req, int roletypeMaster) {
        List<ReportMasterDearSaleRes> list =  sysOrderMapper.selectMasterDealerSalesDetail(req.getStartTime(),req.getEndTime(),req.getOrderState(),req.getDealerName(),roletypeMaster,req.getStart(),req.getEnd(),req.getDealerId());
        return new AsyncResult<>(list);
    }

    @Async
    public Future<ReportOnlineVo> queryProductSalesReportToTalAmt(ReportProductSaleReq req, int roleType) {
        ReportOnlineVo bigDecimal =  sysOrderMapper.selectProductSalesReportToTalAmt(req.getStartTime(),req.getEndTime(),req.getProductName(),roleType);
        return new AsyncResult<>(bigDecimal);
    }

    @Async
    public Future<List<ReportProductSaleRes>> queryProductSalesReportDetail(ReportProductSaleReq req, int roleType) {
        List<ReportProductSaleRes> list =  sysOrderMapper.selectProductSalesReportDetail(req.getStartTime(),req.getEndTime(),req.getProductName(),roleType,req.getStart(),req.getEnd());
        return new AsyncResult<>(list);
    }
}
